package cl.trineo.parkingspace;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.simple.JSONObject;

import cl.trineo.parkingspace.points.Administradora;
import cl.trineo.parkingspace.points.ParkingSpace;
import cl.trineo.parkingspace.points.Precio;
import cl.trineo.parkingspace.points.TipoUbicacion;
import cl.trineo.parkingspace.points.UbicacionActual;


/**
 * Servlet implementation class LocalizacionActual
 */
public class LocalizacionActual extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public LocalizacionActual() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		System.out.println(request.getParameter("latitud"));
		System.out.println(request.getParameter("longitud"));
		
		TipoUbicacion tipoUbicacion = new TipoUbicacion("Ubicacion Actual","Ubicacion Actual");
		
		ArrayList<ParkingSpace> parkingsSpace = new ArrayList<ParkingSpace>();
		
		TipoUbicacion tipoUbicacion1 = new TipoUbicacion("Ubicacion 1","Ubicacion 1");
		TipoUbicacion tipoUbicacion2 = new TipoUbicacion("Ubicacion 2","Ubicacion 2");
		
		Precio precio = new Precio("30","1","2","3","4","5","6","7","8","9","10","11","24","$3000 x 30 Minutos");
		
		ParkingSpace parkingSpace = new ParkingSpace("parking1","parking1","-70.648441","-33.451066",tipoUbicacion1,"grande","Lunes a Viernes 08:00 a 24:00 Hrs", 3, "$5000", new Administradora("Estacionamientos Saba, Chile","Estacionamientos Saba, Chile"), precio, "Av Providencia 1171, las Condes","1");
		ParkingSpace parkingSpace2 = new ParkingSpace("parking2","parking2","-70.645995","-33.445032",tipoUbicacion2,"grande","Lunes a Viernes 08:00 a 24:00 Hrs", 2, "$5000", new Administradora("Estacionamientos Saba, Chile","Estacionamientos Saba, Chile"), precio, "Av Providencia 1162, las Condes", "2");
		
		parkingsSpace.add(parkingSpace);
		parkingsSpace.add(parkingSpace2);
		
		
		UbicacionActual actual = new UbicacionActual("Centro","Centro","14,2","14,2", tipoUbicacion, parkingsSpace);
		
		JSONObject obj=new JSONObject();
		obj.put("actual",actual);
		System.out.print(obj);
		
		
		ServletOutputStream salida = response.getOutputStream();

		response.setContentType("text/html");

		//String cadena = req.getParameter("TEXTO");

		salida.println (obj.toString());

		}


	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
